package com.jisheng.xb.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.jisheng.xb.dao.ArticleMapper;
import com.jisheng.xb.entity.Article;

@Controller
@RequestMapping("menu")
public class MenuController {
	
	@Autowired
	private ArticleMapper articleMapper;
	
	@RequestMapping(value = {"test"}, method = { RequestMethod.POST,RequestMethod.GET})
	public Model test(Model model,
			HttpServletRequest request,
			HttpServletResponse response){
		model.addAttribute("name", "this is user");
		return model;
	}
	
	@RequestMapping(value = {"index"}, method = { RequestMethod.POST,RequestMethod.GET})
	public ModelAndView index(Model model,
			HttpServletRequest request,
			HttpServletResponse response){
		List<Article> list = articleMapper.selectAll();
		ModelAndView mv = new ModelAndView("index").addObject("list", list);
		return mv;
	}
	
	@RequestMapping(value = {"about"}, method = { RequestMethod.POST,RequestMethod.GET})
	public ModelAndView about(Model model,
			HttpServletRequest request,
			HttpServletResponse response){
		ModelAndView mv = new ModelAndView("about");
		return mv;
	}
	
	@RequestMapping(value = {"contact"}, method = { RequestMethod.POST,RequestMethod.GET})
	public ModelAndView contact(Model model,
			HttpServletRequest request,
			HttpServletResponse response){
		ModelAndView mv = new ModelAndView("contact");
		return mv;
	}
	
	@RequestMapping(value = {"write"}, method = { RequestMethod.POST,RequestMethod.GET})
	public ModelAndView write(Model model,
			HttpServletRequest request,
			HttpServletResponse response){
		ModelAndView mv = new ModelAndView("write");
		return mv;
	}
	
	@RequestMapping(value = {"single"}, method = { RequestMethod.POST,RequestMethod.GET})
	public ModelAndView single(Model model,
			HttpServletRequest request,
			HttpServletResponse response){
		ModelAndView mv = new ModelAndView("single");
		return mv;
	}
	@RequestMapping(value = {"old"}, method = { RequestMethod.POST,RequestMethod.GET})
	public ModelAndView old(Model model,
			HttpServletRequest request,
			HttpServletResponse response){
		List<Article> list = articleMapper.selectAll();
		ModelAndView mv = new ModelAndView("old").addObject("list", list);
		return mv;
	}
	
	@RequestMapping(value = {"shares"}, method = { RequestMethod.POST,RequestMethod.GET})
	public ModelAndView shares(Model model,
			HttpServletRequest request,
			HttpServletResponse response){
		ModelAndView mv = new ModelAndView("shares");
		return mv;
	}
	
	
}
